package com.itqf.connecter;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DbConnection {
    static Connection conn=null;
    public static Connection getConnection() {
        try {
            String url="jdbc:mysql://127.0.0.1:3306/xiaomistore?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
            String user="root";
            String password="123456";
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(url, user, password);
        }catch(Exception e) {
            e.printStackTrace();
        }
        return conn;
    }


    public static void close(ResultSet rs, PreparedStatement ps) {
        try {
            if(rs!=null)
                rs.close();
            if(ps!=null)
                ps.close();
            if(conn!=null)
                conn.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}
